import { createSlice } from "@reduxjs/toolkit";

const initialState = {
  waterModel: {
    trainingTime: null,
    completionTime: null,
    timeRange: [],
    progress: 0,
    loading: false,
  },
  paramsModel: {
    trainingTime: null,
    completionTime: null,
    timeRange: [],
    progress: 0,
    loading: false,
  },
};

const TrainModelSlice = createSlice({
  name: "trainModel",
  initialState,
  reducers: {
    updateWaterModel(state, action) {
      state.waterModel = { ...state.waterModel, ...action.payload };
    },
    updateParamsModel(state, action) {
      state.paramsModel = { ...state.paramsModel, ...action.payload };
    },
    clearModels(state) {
      state.waterModel = initialState.waterModel;
      state.paramsModel = initialState.paramsModel;
    },
  },
});

export const { updateWaterModel, updateParamsModel, clearModels } =
  TrainModelSlice.actions;
export default TrainModelSlice.reducer;
